package com.dong.config;

import com.dong.interceptor.MyInterceptor;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.FilterType;
import org.springframework.stereotype.Controller;
import org.springframework.web.servlet.config.annotation.*;

/**
 * <h1></h1>
 * 可以使用{@link WebMvcConfigurerAdapter} 代替{@link WebMvcConfigurer}
 * @author : dzj
 * @create: 2020-05-05 01:19
 */
@ComponentScan(useDefaultFilters = false
        ,includeFilters = {@ComponentScan.Filter(type = FilterType.ANNOTATION,classes = Controller.class)}
        ,value = "com.dong")
@EnableWebMvc
public class AppConfig extends WebMvcConfigurerAdapter {
    //定制视图解析器

    @Override
    public void configureViewResolvers(ViewResolverRegistry registry) {
        registry.jsp("/WEB-INF/jsp/",".jsp");
    }

    /**
     * 允许tomcat 处理mvc 无法处理的请求   静态资源访问
     * <mvc:default-servlet-heandler/>
     * @param configurer
     */
    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new MyInterceptor()).addPathPatterns("/**");
    }
}
